#include "meshcontroller.h"

MeshController::MeshController(MainWindow* mw, QObject *parent) :
    QObject(parent)
{
    m_canvas = new Canvas();

    connect(m_canvas, SIGNAL(draw()),
            this, SLOT(draw()));
    connect(m_canvas, SIGNAL(leftPressed(QVector2D)),
            this, SLOT(leftPressed(QVector2D)));
    connect(m_canvas, SIGNAL(leftReleased(QVector2D)),
            this, SLOT(leftReleased(QVector2D)));



    bezier.addControlPoint(QVector2D(-3,  2));
    bezier.addControlPoint(QVector2D(-2, -2));
    bezier.addControlPoint(QVector2D( 0,  2));
    bezier.addControlPoint(QVector2D( 2,  -2.5));

    mw->setCanvas(m_canvas);
    mw->show();

}

void MeshController::draw()
{
    m_canvas->clear();
    //m_canvas->drawLines(bezier.getLines(), qRgb(255,0,0));
    //m_canvas->drawLines(bezier.getPolyLine(30), qRgb(0,0,0));
    bezier.getPolyLine(m_canvas);
    m_canvas->update();
}

void MeshController::leftReleased(QVector2D v)
{
    bezier.addControlPoint(v);
    draw();
}

void MeshController::leftPressed(QVector2D v)
{
}
